﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Asplode
{
    public class AsplodeMap
    {
        public Model model;

        private Matrix[] walls = new Matrix[4];
        private Matrix floor = new Matrix();

        private int _width;
        public int width
        {
            get
            {
                return _width;
            }
            set
            {
                _width = value;
                redoTransforms();
            }
        }
        
        private Matrix _projection;
        public Matrix CameraProjection
        {
            get
            {
                return _projection;
            }
        }        

        public int _depth;
        public int depth
        {
            get
            {
                return _depth;
            }
            set
            {
                _depth = value;
                redoTransforms();
            }
        }

        public Vector3 CameraPosition { get; set; }

        public AsplodeMap(GraphicsDevice GraphicsDevice)
        {
            this.width = 5;
            this.depth = 5;
            _projection = new Matrix();
            _projection = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.ToRadians(45.0f),
                GraphicsDevice.Viewport.AspectRatio, 1.0f, 10000f);
        }

        public void LoadContent(ContentManager cm)
        {
             model = cm.Load<Model>("Models\\cube");
        }        

        private void redoTransforms()
        {
            //floor
            floor = Matrix.CreateScale(width, 1, depth);
                //Matrix.CreateTranslation(0,-0.5f,0);

            // deep wall


            //walls[0] = Matrix.CreateScale(width, 5, depth)
               //        *Matrix.CreateTranslation(;


        }

        public void Draw(GraphicsDevice GraphicsDevice, float camRotation)
        {
            //redoTransforms();
            foreach(ModelMesh mesh in model.Meshes){
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.View = Matrix.CreateLookAt(CameraPosition, Vector3.Zero, Vector3.Up);
                    effect.Projection = CameraProjection;
                    effect.World = Matrix.CreateScale(800.0f, 1.0f, 600.0f)*Matrix.CreateRotationY(camRotation);
                    effect.EnableDefaultLighting();
                    effect.AmbientLightColor = Color.DarkGray.ToVector3();
                }
                mesh.Draw();
            }
        }
    }
}
